<template>

  <el-table
      :data="tableData"
      ref="table"
      empty-text="无志愿提交"
      style="width: 100%">
    <el-table-column
        fixed
        label="志愿"
        type="index"
        width="50"
    />
    <el-table-column
        prop="mentorname"
        label="姓名"
    >
    </el-table-column>
    <el-table-column
        prop="gender"
        label="性别"
    >
    </el-table-column>
    <el-table-column
        prop="mentorcollege"
        label="导师学院"
    >
    </el-table-column>
    <el-table-column
        prop="status"
        label="申请状态"
    >
      <template v-slot:="scope">
        {{ scope.row.status === "rejected" ? "申请被拒绝" : scope.row.status === "accepted" ? "导师接受了你的申请" : scope.row.status === "ended" ? "已结束" : "等待导师处理"}}
      </template>
    </el-table-column>

  </el-table>
</template>

<script>
export default {
  data() {
    return {
      tableData: [],
    }
  },

  mounted() {
    this.$http({
      url: 'student/mentor-choices',
      method: 'get'
    }).then(({data}) => {
      if (data.data !== null) {
        let statusDict = {
          [data.firstchoice]: data.firststatus,
          [data.secondchoice]: data.secondstatus,
          [data.thirdchoice]: data.thirdstatus,
        }
        this.tableData = data.mentors
        this.tableData.forEach(mentor => {
          mentor.status = statusDict[mentor.id] || null; // 如果 id 不在字典中，status 为 null
        });
      }
    }).catch(error => {
      console.error("请求出错", error);
      throw error; // 重新抛出错误以便上层处理
    });
  }

}
</script>

<style scoped lang="scss">

.el-table {
  margin: 0 !important; /* 或者根据需要设置 */
  padding: 0 !important; /* 或者根据需要设置 */
}

</style>
